package com.cyw.baselibrary.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

public class CommonPagerAdapter<T extends View> extends PagerAdapter {
	private List<T> mListViews;

	public CommonPagerAdapter(List<T> mListViews) {
		this.mListViews = mListViews;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView(mListViews.get(position));
	}
	
	public void resetData(List<T> newData) {
		this.mListViews.clear();
		this.mListViews.addAll(newData);
		notifyDataSetChanged();
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		View view = mListViews.get(position);
		container.addView(view, 0);
		return view;
	}

	@Override
	public int getCount() {
		return mListViews.size();
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == arg1;
	}
}
